package com.example.demo.admin.test.feign;/**
 * Created by kete on 2018-09-14.
 */

import feign.*;
/**
 * 作者：kete
 * 创建时间：2018-09-14 10:41
 * 功能描述：
 * 版本：
 */
public class WebserviceExample {

    interface TestService{

        @RequestLine("POST /IAMService/webservice/service")
        @Headers("Content-Type: application/xml")
        @Body("<request><accountNo>{accountNo}</accountNo><channleId>{channleId}</channleId>" +
                "<csrId>{csrId}</csrId><requestSeq>{requestSeq}</requestSeq></request>")
        String testService(@Param("accountNo") String accountNo,@Param("channleId")String channleId
                ,@Param("csrId") String csrId,@Param("requestSeq") String requestSeq);

        static TestService connect() {

            return Feign.builder()
                    .encoder(new XmlEncoder())
                    .logger(new Logger.ErrorLogger())
                    .logLevel(Logger.Level.BASIC)
                    .target(TestService.class, "http://10.145.199.147:9080");
        }

    }

    interface CsbService{

        @RequestLine("POST /")
        @Headers("Content-Type: application/xml")
        @Body("<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                "xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
                "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "+
                "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">"+
                " <SOAP-ENV:Body>"+
                " <m:HSS-REQUEST xmlns:m=\"http://tempuri.org/NS.xsd\">"+
                " <hss-req>  " +
                " <MID>154</MID>" +
                " <UID>CSB_USER</UID>" +
                " <PWD>aji$483ji*dw29sd</PWD>" +
                "    <SCID>PROC_HF_QUERY</SCID> " +
                "   <SIG>String</SIG> " +
                "   <RVS1>String</RVS1> " +
                "   <RVS2>String</RVS2> " +
                "    <DATA> " +
                "    <REQ>" +
                "   <I_SERVICE_NBR>{serverNo}</I_SERVICE_NBR>" +
                "    <I_MONTH>{month}</I_MONTH>" +
                "   </REQ> " +
                "    </DATA> " +
                "   </hss-req>" +
                " </m:HSS-REQUEST>" +
                "  </SOAP-ENV:Body> " +
                " </SOAP-ENV:Envelope> "+
                "")
        String testService(@Param("serverNo")String serverNo,@Param("month")String month);

        static CsbService connect(){
            return Feign.builder()
                    .encoder(new XmlEncoder())
                    .logger(new Logger.ErrorLogger())
                    .logLevel(Logger.Level.BASIC)
                    .target(CsbService.class, "http://10.7.70.216:10000");
        }
    }

    interface IamServiceWebService{

        @RequestLine("POST /IAMebillServerWeb/esb/webservice/PrintInvoiceService")
        @Headers("Content-Type: application/xml;charset=UTF-8")
        @Body("{body}")
        String query(@Param("body")String body);

        static IamServiceWebService connect(){
            return Feign.builder()
                    .encoder(new XmlEncoder())
                    .logger(new Logger.ErrorLogger())
                    .logLevel(Logger.Level.BASIC)
                    .target(IamServiceWebService.class, "http://127.0.0.1:8888");
        }
    }

    public static String getSuccess(){
        String body ="";
        body+="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://webservice.billprint.ideal.com/\">"+
                "<soapenv:Header/>"+
                "<soapenv:Body>"+
                "<web:query>"+
                "<AccNbr>80825729022</AccNbr>"+
                "<DestinationAttr>0</DestinationAttr>"+
                "<BillingCycle>201810</BillingCycle>"+
                "<QueryFlag>0</QueryFlag>"+
                "<Channel>0</Channel>"+
                "</web:queryResult>"+
                "</soapenv:Body>"+
                "</soapenv:Envelope>";
        return body;
    }

    public static void main(String[] args) {
        IamServiceWebService test = IamServiceWebService.connect();


        String body = getSuccess();

        System.out.println(body);

        String str = test.query(body);

        System.out.println(str);

//        TestService test = TestService.connect();
//
//        String str = test.testService("69090078010","cwb","686","12345678");
//
//        System.out.println(str);


    }
}
